import React, {useState, useRef, useEffect} from 'react';
import moment from 'moment'
import { history } from 'umi'
import { List,Icon } from 'antd-mobile'
import { storage,LOCALSTATE } from '@/utils';
import Empty from '@/components/Empty'
import {exampaperList,getAnswerExamRecord} from '@/services/edu'
import style from './index.less'



function History() {
  const [list,setList] = useState([]);
  const local = storage.get(LOCALSTATE,true)
  
  const getData = async () => {
    
    const payload = {
      pageIndex:1,
      pageSize:20,
      subjectId:local.currentSubjectId
    };
    const res = await getAnswerExamRecord(payload);
    if (res.code === 1){
      setList(res.response?.list||[])
    }

    // if (Array.isArray(response.data)) return response.data;
    // setList([{status:1,title:'第一章',time:''},
    // {status:0,title:'第一章'},
    // {status:1,title:'第一章'},
    // {status:1,title:'第一章'},
    // {status:1,title:'第一章'},
    // {status:1,title:'第一章'},
    // {status:1,title:'第一章'}])
  };
  useEffect(()=>{
    getData()
  },[])
  const renderCorrect =(data)=>{
    const {
      questionCorrect,
      questionCount

    } =data
    // Math.round((1/3) * 10000) / 100
    return Math.floor(questionCorrect/questionCount*10000)/100+'%'
  }
 
  return (
    <div>
      <div className={style.history}>
        {list.length>0?<List>
          {
            list.map((item,i)=>(item.recordOrder?<List.Item onClick={()=>history.push(`/history/detail?id=${item.id}`)}
             extra={<div className={style.status}><span>正确率 {item.correctPercent||'-'}% </span><span>{item.status===2?'已完成':`${item.recordOrder}/${item.recordSum}`}</span></div>} arrow="horizontal">
              <span>{moment(item.examTime).format('YYYY-MM-DD')} </span>
            </List.Item>:<></>))
          }
        </List>:<Empty/>}
      </div>
    </div>
  );
}

export default History;
